package system.samples;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;

import client.ClientNavigator;
import client.Command;

public class Help extends Command {
	private ClientNavigator navigator;

	public Help(ClientNavigator navigator) {
		super("help");
		this.navigator = navigator;
	}
	
	@Override
	protected void doFunction() {
		HashMap commands = new HashMap();
		for(Command command : navigator.getCommandMap().values()) {
			HashMap commandMap = new HashMap();
			ArrayList parameterList = new ArrayList();
			for(String parameter : command.getRequiredParameterNames())
				parameterList.add(parameter);
			if(parameterList.size() > 0)
				commandMap.put("requiredParameters", parameterList);
			commands.put(command.getName(), commandMap);
		}		
		TreeMap sortedCommands = new TreeMap(commands);
		
		ret("commands", sortedCommands);
	}
}